package com.summer_administration.mapper;

import com.summer_administration.pojo.GroupExpenseDTO;
import com.summer_administration.pojo.Groupe;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface GroupeMapper {

    @Insert("INSERT INTO groupe(group_id, group_name, group_attr, member_num, leader, " +
            "member1, member2, member3, member4, create_user, create_time, update_time) " +
            "VALUES(#{groupId}, #{groupName}, #{groupAttr}, #{memberNum}, #{leader}, " +
            "#{member1}, #{member2}, #{member3}, #{member4}, #{createUser}, #{createTime}, #{updateTime})")
    void add(Groupe groupe);

    @Select("SELECT *, member_num AS groupNumber FROM groupe WHERE create_user = #{userId}")
    List<Groupe> listByUser(Integer userId);

    @Update("UPDATE groupe SET " +
            "group_id = #{groupId}, " +
            "group_name = #{groupName}, " +
            "group_attr = #{groupAttr}, " +
            "member_num = #{memberNum}, " +
            "leader = #{leader}, " +
            "member1 = #{member1}, " +
            "member2 = #{member2}, " +
            "member3 = #{member3}, " +
            "member4 = #{member4}, " +
            "update_time = #{updateTime} " +
            "WHERE id = #{id}")
    void update(Groupe groupe);

    @Delete("DELETE FROM groupe WHERE id = #{id}")
    void delete(Integer id);

    @Select("SELECT * FROM groupe WHERE id = #{id}")
    Groupe getById(Integer id);

    @Select("SELECT COUNT(*) FROM groupe WHERE group_id = #{groupId}")
    boolean existsByGroupId(String groupId);

    @Select("SELECT COUNT(*) FROM commune_arrange WHERE group_id = #{groupId}")
    boolean hasRelatedActivities(String groupId);

    @Select("SELECT group_name FROM groupe WHERE group_id = #{groupId}")
    String findGroupNameByGroupId(String groupId);

    @Select("SELECT group_id FROM groupe WHERE group_name = #{groupeName}")
    String findGroupIdByGroupName(String groupeName);

    //String findGroupIdByGroupName(String groupeName);
}